package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.QueryDoctorListBean;
import com.itboye.jinpuyiyuan.bean.QueryDoctorListBeanNew;
import com.itboye.jinpuyiyuan.bean.RegisterDoctorDetail;
import com.itboye.jinpuyiyuan.bean.RegisterHospitalBean;
import com.itboye.jinpuyiyuan.utils.sputil.Const;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/9 0009.
 */

public class RegisterDoctorDetailAdapter extends BaseAdapter {
    private ArrayList<QueryDoctorListBeanNew.DoctorItem> list;
    private Context context;
    private LayoutInflater inflater;


    public  RegisterDoctorDetailAdapter(Context context,ArrayList<QueryDoctorListBeanNew.DoctorItem> list){
        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      String strenth="";
      RegisterDoctorDetailHolder registerDoctorDetailHolder;
        if (convertView==null){
            registerDoctorDetailHolder=new RegisterDoctorDetailHolder();
            convertView=inflater.inflate(R.layout.item_registerdoctorlist,parent,false);
            registerDoctorDetailHolder.doctorName=convertView.findViewById(R.id.doctorName);
            registerDoctorDetailHolder.jobName=convertView.findViewById(R.id.jobName);
//            registerDoctorDetailHolder.doctorCity=convertView.findViewById(R.id.doctorCity);
            registerDoctorDetailHolder.doctorEvaluate=convertView.findViewById(R.id.doctorEvaluate);
//            registerDoctorDetailHolder.doctorStrengths=convertView.findViewById(R.id.doctorStrengths);
            registerDoctorDetailHolder.tvRegister=convertView.findViewById(R.id.tvRegister);
            registerDoctorDetailHolder.doctorImg=convertView.findViewById(R.id.doctorImg);
            convertView.setTag(registerDoctorDetailHolder);
        }else {
            registerDoctorDetailHolder= (RegisterDoctorDetailHolder) convertView.getTag();
        }
        registerDoctorDetailHolder.jobName.setText(list.get(position).getDept_name());
        registerDoctorDetailHolder.doctorName.setText(list.get(position).getName());
        registerDoctorDetailHolder.doctorEvaluate.setText(list.get(position).getJob_title());
//        registerDoctorDetailHolder.doctorCity.setText(list.get(position).getCity());
//        for (int i=0;i<list.get(position).getSect_list().size();i++){
//            strenth+=list.get(position).getSect_list().get(i).getCname();
//            if (i!=(list.get(position).getSect_list().size()-1)){
//               strenth+=" , ";
//            }
//        }
//        registerDoctorDetailHolder.doctorStrengths.setText(strenth);
//        registerDoctorDetailHolder.doctorProvince.setText(list.get(position).getProvince());
//        Log.d("==========",list.get(position).getRealname()+"=="+list.get(position).getDt_level_name()+"=="+list.get(position).getCity()+"==");
        registerDoctorDetailHolder.tvRegister.setVisibility(View.GONE);
        if (position==(list.size()-1)){
            registerDoctorDetailHolder.tvRegister.setText("挂号结束");
        }else {
            registerDoctorDetailHolder.tvRegister.setText("挂号");
        }
        Glide.with(context).load(Const.DoctorImg+list.get(position).getUid()).into(registerDoctorDetailHolder.doctorImg);
        return convertView;
    }

    class RegisterDoctorDetailHolder {
        TextView doctorName,
//                doctorProvince,
                  jobName,
                doctorEvaluate,
//                doctorStrengths,
                tvRegister;
        ImageView doctorImg;

    }

    public void addData(ArrayList<QueryDoctorListBeanNew.DoctorItem> list){
        this.list=list;
        this.notifyDataSetChanged();
    }

}
